/*
* Copyright (c) 2010 The Turing Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* Except as contained in this notice, the name(s) of the above
* copyright holders shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
 */

package     userinterface;
import      simulator.*;


/**
 * The region of model space which is visible in the x, y, and z projections diplayed
 * on the user interface.
 */
public class ProjectionBox {
    private Vector3D    _center;    // Center of ProjectionBox in model space.
    private int         _width;     // X and Y dimentions in pixels.
    private int         _height;    // Z dimention in pixels.
    private Double      _scale;     // Meters/pixel.

    /**
     * Defines the 3D space that will be projected onto the ProjectionPanel.
     */
    public ProjectionBox() {
        _center = new Vector3D();
        _center.cartesianSet(50.0, 50.0, 0.0);
        _width = 300;
        _height = 300;
        _scale = 1.0;
    }

    /**
     * Returns the specified coordinate of the center of the projection box.
     * @param coordinate
     * @return
     */
    public Double getCenter(int coordinate) {
        return _center.getComponent(coordinate);
    }

    /**
     * Returns the scale of the projection box.
     * @return
     */
    public Double getScale(){
        return _scale;
    }

    /**
     * Returns the width of the projection box.
     * @return
     */
    public int getWidth() {
        return _width;
    }

        /**
     * Returns the height of the projection box.
     * @return
     */
    public int getHeight() {
        return _height;
    }

    /**
     * Recenters and scales the projection box so that all nodes are
     * contained within the projection box.
     * @param model
     */
    public void reframeModel(Model model) {
        _center = model.getCenter();
        _scale = (double)_width / model.getDiameter(_center) * 0.75;
        _height = _width;
    }
}
